import DList from "@/components/dlist";
export default {
  data() {
    return {
      keyword: "",
      dataList: [],
      loading: false,
      finished: false,
      page: 1,
      id: "",
      type: ""
    };
  },
  activated() {
    this.id = this.$route.params.id;
    this.type = this.$route.params.type;
    this.dataList = [];
    this.loading = false;
    this.finished = false;
    this.page = 1;
    this.keyword = "";
    this.getData();
  },
  methods: {
    clickShow(index,value) {
      this.$set(this.dataList[index],"ishow",value);
    },
    gotoCustomerList(id) {
      if(this.type) {
        this.$router.push(this.fun.getUrl('customerStatisticsList',{id,type : 1}));
      }
    },
    async getData(val) {
      if (this.loading === true || this.finished === true) {
        return;
      }
      this.loading = true;
      let { data , result, msg } = await $http.post("plugin.region-external-reward.frontend.controllers.client.client.childClientList", { 
        child_id: this.id,
        page: this.page,
        keyword: this.keyword,
        level_limit: this.type
      });
      if (result) {
        if(val == "loading") {
          this.dataList.push(...data.list.data);
        }else {
          this.dataList = data.list.data;
        }
        if (data.list.data.length === 0 || data.list.data.length < data.list.per_page || data.list.current_page === data.list.last_page) {
          this.finished = true;
        }
        this.page++;
        this.loading = false;
      } else {
        this.$toast(msg);
      }
    },
    onLoad() {
      this.getData("loading");
    },
    searchData() {
      clearTimeout(this.timer);
      this.timer = setTimeout(() => {
        this.dataList = [];
        this.loading = false;
        this.finished = false;
        this.page = 1;
        this.getData(); //防抖
      }, 300);
    }
  },
  components: { DList }
};
